package cn.lijigou.shopping;

import java.util.ArrayList;
import java.util.List;

import cn.lijigou.shopping.util.APNManage;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

public class MActivity extends Activity {
	public APNManage apn = null;
	public static ConnectivityManager cm = null;
	public static NetworkInfo network = null;
	public final static List<Activity> activityList = new ArrayList<Activity>();
	public static Activity activity = null;
	public static Handler netWorkHander = new Handler(){
		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			Toast.makeText(activity, R.string.network_connection_error, 1).show();
			this.removeMessages(msg.what);
		}
	};
	  @Override
	  protected void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			if(apn == null){
				apn = new  APNManage(this);
			}
			activity = this;
			activityList.add(this);
			overridePendingTransition(R.anim.push_in,R.anim.push_out);
	  }
	public static boolean getNetWork(){
		if(cm==null){
			cm = (ConnectivityManager)activity.getSystemService(Context.CONNECTIVITY_SERVICE);   
		}
		network = cm.getActiveNetworkInfo();  
		if(network != null){   
			return network.isAvailable();
		}else{
			netWorkHander.sendEmptyMessage(0);
		}
		return false;
	}
	@Override
	protected void onDestroy() {
		super.onDestroy();
	}
	public static void killMyProcess()
	  {
		  for (Activity activity : activityList)
		  {
			  activity .finish();
		  }
		  android.os.Process.killProcess(android.os.Process.myPid());
	  }
}
